import type { App } from "vue";
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },

  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "Dashboard",
        meta: {
          title: "dashboard",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
      // {
      //   path: "dashboard2",
      //   component: () => import("@/views/dashboard/index_copy.vue"),
      //   // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
      //   // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
      //   name: "Dashboard2",
      //   meta: {
      //     title: "dashboard2",
      //     icon: "homepage",
      //     affix: true,
      //     keepAlive: true,
      //   },
      // },
      {
        path: "401",
        component: () => import("@/views/error-page/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error-page/404.vue"),
        meta: { hidden: true },
      },
    ],
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    name: "dashboard2",
    meta: {
      title: "dashboard2",
      icon: "document",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "dashboard2",
        component: () => import("@/views/dashboard/chartTotal.vue"),
        name: "dashboard2",
        meta: {
          title: "dashboard2",
          icon: "document",
          hidden: false,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/system",
    component: Layout,
    redirect: "/system/user",
    name: "/system",
    meta: {
      title: "系统管理",
      icon: "system",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "user",
        component: () => import("@/views/system/user/index.vue"),
        name: "User",
        meta: {
          title: "用户管理",
          icon: "user",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      // {
      //   path: "role",
      //   component: () => import("@/views/system/role/index.vue"),
      //   name: "Role",
      //   meta: {
      //     title: "角色管理",
      //     icon: "role",
      //     hidden: false,

      //     keepAlive: true,
      //     alwaysShow: false,
      //     params: null,
      //   },
      // },
      // {
      //   path: "menu",
      //   component: () => import("@/views/system/menu/index.vue"),
      //   name: "Menu",
      //   meta: {
      //     title: "菜单管理",
      //     icon: "menu",
      //     hidden: false,

      //     keepAlive: true,
      //     alwaysShow: false,
      //     params: null,
      //   },
      // },
      // {
      //   path: "dept",
      //   component: () => import("@/views/system/dept/index.vue"),
      //   name: "Dept",
      //   meta: {
      //     title: "部门管理",
      //     icon: "tree",
      //     hidden: false,

      //     keepAlive: true,
      //     alwaysShow: false,
      //     params: null,
      //   },
      // },
      // {
      //   path: "dict",
      //   component: () => import("@/views/system/dict/index.vue"),
      //   name: "Dict",
      //   meta: {
      //     title: "字典管理",
      //     icon: "dict",
      //     hidden: false,

      //     keepAlive: true,
      //     alwaysShow: false,
      //     params: null,
      //   },
      // },
    ],
  },
  {
    path: "/number",
    component: Layout,
    // redirect: "/number/number2",
    name: "/number",
    meta: {
      title: "号码管理",
      icon: "tree",
      hidden: false,
      alwaysShow: true,
      params: null,
    },
    children: [
      {
        path: "list", //和侧边菜单栏path保持一致
        component: () => import("@/views/number/number1/index.vue"),
        name: "Number1",
        meta: {
          title: "号码管理1",
          icon: "table",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "list2",
        component: () => import("@/views/number/number2/index.vue"),
        name: "Number2",
        meta: {
          title: "号码管理2",
          icon: "table",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/phoneMange", // 父路由
    component: Layout,
    redirect: "/phoneMange/list",
    name: "/phoneMange",
    meta: {
      title: "gps管理",
      icon: "tree",
      hidden: false,
      alwaysShow: true,
      params: null,
    },
    children: [
      {
        path: "list",
        component: () => import("@/views/phoneManage/index.vue"),
        name: "PhoneManage",
        meta: {
          title: "gps管理",
          icon: "table",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/AbsoTotal", // 父路由
    component: Layout,
    redirect: "/AbsoTotal/list",
    name: "/AbsoTotal",
    meta: {
      title: "abso",
      icon: "tree",
      hidden: false,
      alwaysShow: true,
      params: null,
    },
    children: [
      {
        path: "list",
        component: () => import("@/views/abso/orderTotal/index.vue"),
        name: "AbsoTotal",
        meta: {
          title: "abso订单汇总统计",
          icon: "table",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "list3",
        component: () => import("@/views/abso/user_typeTotal/index.vue"),
        name: "user_typeTotal",
        meta: {
          title: "abso订单会员类型汇总统计",
          icon: "table",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "list4",
        component: () => import("@/views/abso/produce/index.vue"),
        name: "produceTotal",
        meta: {
          title: "abso图表",
          icon: "table",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "list2",
        component: () => import("@/views/abso/userTotal/index.vue"),
        name: "userTotal",
        meta: {
          title: "abso收货地址汇总统计",
          icon: "table",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },

  {
    path: "/cdzinfo",
    component: Layout,
    redirect: "/cdzinfo/list",
    name: "/cdzinfo",
    meta: {
      title: "充电桩订单",
      icon: "document",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "list",
        component: () => import("@/views/cdzinfo/index.vue"),
        name: "cdzinfo",
        meta: {
          title: "充电桩订单",
          icon: "document",
          hidden: false,

          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/payment",
    component: Layout,
    redirect: "payment/list",
    name: "/payment",
    meta: {
      title: "续费管理",
      icon: "document",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "list",
        component: () => import("@/views/payment/index.vue"),
        name: "payment",
        meta: {
          title: "续费管理",
          icon: "document",
          hidden: false,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },

  {
    path: "/cmdb",
    component: Layout,
    name: "/device",
    meta: {
      title: "device",
      icon: "tree",
      hidden: false,
      alwaysShow: true,
      params: null,
    },
    children: [
      {
        path: "client_list", // 子路由
        component: () => import("@/views/cmdb/client/index.vue"),
        name: "client", // 路由的 name 和组件 name 保持一致，路由跳转及缓存可以使用name
        meta: {
          title: "客户管理", //顶部标题
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "room_list", // 子路由
        component: () => import("@/views/cmdb/room/index.vue"),
        name: "room", // 路由的 name 和组件 name 保持一致，路由跳转及缓存可以使用name
        meta: {
          title: "机房管理",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "cabinet_list", // 子路由
        component: () => import("@/views/cmdb/cabinet/index.vue"),
        name: "cabinet", // 路由的 name 和组件 name 保持一致，路由跳转及缓存可以使用name
        meta: {
          title: "机柜信息",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "device_list", //和侧边菜单栏path保持一致
        component: () => import("@/views/cmdb/device/index.vue"),
        name: "device",
        meta: {
          title: "设备详情", //顶部标题
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },

  {
    path: "/api",
    component: Layout,
    name: "/api",
    meta: {
      title: "接口文档",
      icon: "api",
      hidden: false,
      alwaysShow: true,
      params: null,
    },
    children: [
      {
        path: "apifox",
        component: () => import("@/views/demo/api/apifox.vue"),
        name: "Apifox",
        meta: {
          title: "Apifox",
          icon: "api",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/doc",
    component: Layout,
    redirect: "https://juejin.cn/post/7228990409909108793",
    name: "/doc",
    meta: {
      title: "平台文档",
      icon: "document",
      hidden: false,

      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "internal-doc",
        component: () => import("@/views/demo/internal-doc.vue"),
        name: "InternalDoc",
        meta: {
          title: "平台文档(内嵌)",
          icon: "document",
          hidden: false,

          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "https://juejin.cn/post/7228990409909108793",
        name: "Https://juejin.cn/post/7228990409909108793",
        redirect: "/",
        meta: {
          title: "平台文档(外链)",
          icon: "link",
          hidden: false,

          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/multi-level",
    component: Layout,
    name: "/multiLevel",
    meta: {
      title: "多级菜单",
      icon: "cascader",
      hidden: false,

      alwaysShow: true,
      params: null,
    },
    children: [
      {
        path: "multi-level1",
        component: () => import("@/views/demo/multi-level/level1.vue"),
        name: "MultiLevel1",
        meta: {
          title: "菜单一级",
          icon: "",
          hidden: false,

          alwaysShow: true,
          params: null,
        },
        children: [
          {
            path: "multi-level2",
            component: () =>
              import("@/views/demo/multi-level/children/level2.vue"),
            name: "MultiLevel2",
            meta: {
              title: "菜单二级",
              icon: "",
              hidden: false,

              alwaysShow: false,
              params: null,
            },
            children: [
              {
                path: "multi-level3-1",
                component: () =>
                  import(
                    "@/views/demo/multi-level/children/children/level3-1.vue"
                  ),
                name: "MultiLevel31",
                meta: {
                  title: "菜单三级-1",
                  icon: "",
                  hidden: false,

                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "multi-level3-2",
                component: () =>
                  import(
                    "@/views/demo/multi-level/children/children/level3-2.vue"
                  ),
                name: "MultiLevel32",
                meta: {
                  title: "菜单三级-2",
                  icon: "",
                  hidden: false,

                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
            ],
          },
        ],
      },
    ],
  },
  {
    path: "/component",
    component: Layout,
    name: "/component",
    meta: {
      title: "组件封装",
      icon: "menu",
      hidden: false,

      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "curd",
        component: () => import("@/views/demo/curd/index.vue"),
        name: "Curd",
        meta: {
          title: "增删改查",
          icon: "",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "table-select",
        component: () => import("@/views/demo/table-select/index.vue"),
        name: "TableSelect",
        meta: {
          title: "列表选择器",
          icon: "",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "wang-editor",
        component: () => import("@/views/demo/wang-editor.vue"),
        name: "WangEditor",
        meta: {
          title: "富文本编辑器",
          icon: "",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "upload",
        component: () => import("@/views/demo/upload.vue"),
        name: "Upload",
        meta: {
          title: "图片上传",
          icon: "",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "icon-selector",
        component: () => import("@/views/demo/icon-selector.vue"),
        name: "IconSelector",
        meta: {
          title: "图标选择器",
          icon: "",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "dict-demo",
        component: () => import("@/views/demo/dict.vue"),
        name: "DictDemo",
        meta: {
          title: "字典组件",
          icon: "",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/route-param",
    component: Layout,
    name: "/routeParam",
    meta: {
      title: "路由参数",
      icon: "el-icon-ElementPlus",
      hidden: false,
      alwaysShow: true,
      params: null,
    },
    children: [
      {
        path: "route-param-type1",
        component: () => import("@/views/demo/route-param.vue"),
        name: "RouteParamType1",
        meta: {
          title: "参数(type=1)",
          icon: "el-icon-Star",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: {
            type: "1",
          },
        },
      },
      {
        path: "route-param-type2",
        component: () => import("@/views/demo/route-param.vue"),
        name: "RouteParamType2",
        meta: {
          title: "参数(type=2)",
          icon: "el-icon-StarFilled",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: {
            type: "2",
          },
        },
      },
    ],
  },
  {
    path: "/function",
    component: Layout,
    name: "/function",
    meta: {
      title: "功能演示",
      icon: "menu",
      hidden: false,

      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "icon-demo",
        component: () => import("@/views/demo/icons.vue"),
        name: "IconDemo",
        meta: {
          title: "Icons",
          icon: "el-icon-Notification",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "/function/websocket",
        component: () => import("@/views/demo/websocket.vue"),
        name: "/function/websocket",
        meta: {
          title: "Websocket",
          icon: "",
          hidden: false,

          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "other/:id",
        component: () => import("@/views/demo/other.vue"),
        name: "Other/:id",
        meta: {
          title: "敬请期待...",
          icon: "",
          hidden: false,

          alwaysShow: false,
          params: null,
        },
      },
    ],
  },

  // 外部链接
  // {
  //   path: "/external-link",
  //   component: Layout,
  //   children: [ {
  //       component: () => import("@/views/external-link/index.vue"),
  //       path: "https://www.cnblogs.com/haoxianrui/",
  //       meta: { title: "外部链接", icon: "link" },
  //     },
  //   ],
  // },
  // 多级嵌套路由
  /* {
         path: '/nested',
         component: Layout,
         redirect: '/nested/level1/level2',
         name: 'Nested',
         meta: {title: '多级菜单', icon: 'nested'},
         children: [
             {
                 path: 'level1',
                 component: () => import('@/views/nested/level1/index.vue'),
                 name: 'Level1',
                 meta: {title: '菜单一级'},
                 redirect: '/nested/level1/level2',
                 children: [
                     {
                         path: 'level2',
                         component: () => import('@/views/nested/level1/level2/index.vue'),
                         name: 'Level2',
                         meta: {title: '菜单二级'},
                         redirect: '/nested/level1/level2/level3',
                         children: [
                             {
                                 path: 'level3-1',
                                 component: () => import('@/views/nested/level1/level2/level3/index1.vue'),
                                 name: 'Level3-1',
                                 meta: {title: '菜单三级-1'}
                             },
                             {
                                 path: 'level3-2',
                                 component: () => import('@/views/nested/level1/level2/level3/index2.vue'),
                                 name: 'Level3-2',
                                 meta: {title: '菜单三级-2'}
                             }
                         ]
                     }
                 ]
             },
         ]
     }*/
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 全局注册 router
export function setupRouter(app: App<Element>) {
  app.use(router);
}

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;
